<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('用户自定义列设置')" />
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	    <div class="mid-content">
	        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	    </div>
	</div>
</div>
<div id="form_d" style="padding:10px 60px 10px 10px;display:none;">
	<form class="post_form">
		<div id="dhtransfer" class="demo-transfer"></div>
	</form>
</div>
<th:block th:include="include :: footer" />
<script type="text/html" id="fieldFrontFixed">
    <input type="checkbox" name="fieldFrontFixed" tIndex="{{d.LAY_TABLE_INDEX}}" value="{{d.fieldFrontFixed}}" lay-skin="switch" lay-text="是|否" lay-filter="setFixed" {{ d.fieldFrontFixed === true ? 'checked' : '' }}>
</script>
<script type="text/html" id="fieldFrontHidden">
    <input type="checkbox" name="fieldFrontHidden" tIndex="{{d.LAY_TABLE_INDEX}}" value="{{d.fieldFrontHidden}}" lay-skin="switch" lay-text="是|否" lay-filter="setHidden" {{ d.fieldFrontHidden === true ? 'checked' : '' }}>
</script>
<script type="text/javascript">
// var moduleTable = parent.moduleTable;//存在一单据两张表的情况下（两个moduleTable）
var moduleTable = window.location.href.split('=')[1];
var dataStr = [];
$(function(){
 	getData("/system/userdefinedfields/list?moduleTable="+moduleTable);	
})
function getData(url){
 	$.get(url,function(data,status){
 		if(data.count == 0){
 			dataStr=[];rend();
 		}else{
			dataStr = [];
 			for(var i=0;i<data.data.length;i++){
 				dataStr.push(data.data[i])
 				if(i==data.data.length-1){
 					rend();
 				}
 			}
 		}
 	});
 }
function rend(){
	layui.use(['table','form','layer','jquery'], function () {
		var $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table;
		$.tablelist.init({
			elem: '#dhtable'
			,page:false
			,limit: dataStr.length
			,initSort: {field: 'fieldFrontOrder',type: 'asc'}
	   		,cols: [[
	   			{type:'numbers', width:50,  title:'序号'},
			    {field:'fieldName', title:'列名', width:140, sort: true, align: 'center'},
			    {field:'fieldFrontFixed', title:'是否固定', width:90, align: 'center', templet:'#fieldFrontFixed'},
			    {field:'fieldFrontHidden', title:'是否隐藏', width:90, align: 'center', templet:'#fieldFrontHidden'},
			    {field:'fieldFrontOrder', title:'列排序', width:95, align: 'center', sort:true, edit: 'text'},
			    {field:'fieldFrontWidth', title:'列宽度', width:95, align: 'center', sort:true, edit: 'text'}
	   		]
			]
	   		,data:dataStr
			,height:'full-' + ( $('.north').height()+36),
		});
	  	//监听开关动作
		form.on('switch(setFixed)', function(obj){
	  	  	var dataindex = $(this).attr('tindex');
	  	  	dataStr[dataindex]['fieldFrontFixed'] = obj.elem.checked
	    });
		form.on('switch(setHidden)', function(obj){
	  	  	var dataindex = $(this).attr('tindex');
	  	  	dataStr[dataindex]['fieldFrontHidden'] = obj.elem.checked
	    });
		//监听修改的数据 
		table.on('edit(ftable)', function(obj){
			var value = obj.value,field = obj.field,data= obj.data;
			if(value < 1)layer.msg("填写的数值必须大于 0 ");
			dataStr = table.cache.dhtable;
		});
	})
}
var callbackdata = function () {
    return dataStr;
}
</script>
</body>
</html>